<template>
  <FullPage class="">
    <VGrid
      ref="vgrid"
      :formConfig="formConfig"
      :tableConfig="tableConfig"
      :proxy="proxy"
      @handleFormBtnClick="handleFormBtnClick"
      @handleTableBtnClick="handleTableBtnClick"
    ></VGrid>
    <RoleFormDialog ref="roleFormDialog" @submit="getTableData"></RoleFormDialog>
  </FullPage>
</template>

<script>
import FullPage from '@/components/FullPage';
import VGrid from '@/components/VGrid';
import RoleFormDialog from './RoleFormDialog';

export default {
  components: {
    FullPage,
    VGrid,
    RoleFormDialog,
  },
  data() {
    return {
      formConfig: {
        props: {
          inline: true,
        },
        btns: [
          {
            key: 'add',
            label: '添加生产任务',
            type: 'primary',
            plain: true,
            icon: 'el-icon-plus',
          },
        ],
      },
      tableConfig: {
        props: {
          border: true,
          stripe: true,
        },
        columnList: [
          {
            prop: 'sales_id',
            label: '生产订单号',
          },
          {
            prop: 'engine_num',
            label: '发动机型号',
          },
          {
            prop: 'product_num',
            label: '产品件号',
          },
          {
            prop: 'product_name',
            label: '产品名称',
          },
          {
            prop: 'output_count',
            label: '生产数量',
          },
          {
            prop: 'standard_num',
            label: '基础装配工艺',
          },
          {
            prop: 'custome_standard_no',
            label: '定制工艺',
          },
          {
            prop: 'allocation',
            label: '分配情况',
            type: 'operation_view',
            filter: {
              1: '已分配',
              0: '未分配',
              default: '无',
            },
            colorFilter: {
              1: '#67C23A',
              0: '#F56C6C',
              default: '#46a6ff',
            },
            btns: [
              {
                key: 'feipei',
                label: '已分配',
              },
            ],
          },
          {
            label: '操作',
            type: 'operation',
            btns: [
              {
                key: 'edit',
                label: '编辑',
              },
              {
                key: 'delete',
                label: '删除',
              },
            ],
          },
        ],
      },
      proxy: {
        list: {
          api: this.$api.ag_production.getList,
        },
        delete: {
          api: this.$api.ag_production.delete,
        },
      },
    };
  },
  methods: {
    handleFormBtnClick(key, params) {
      if (key === 'add') {
        this.$refs.roleFormDialog.show('add');
      }
    },
    handleTableBtnClick(key, row) {
      if (key === 'edit') {
        this.$refs.roleFormDialog.show('edit', row);
      }
      if (key === 'feipei') {
        this.$refs.rolePrivilegeDialog.show(row);
      }
    },

    getTableData() {
      this.$refs.vgrid.getTableData();
    },

    refreshTableData() {
      this.$refs.vgrid.refreshTableData();
    },
  },
};
</script>

<style lang="scss" scoped></style>
